#!/usr/bin/env node

const log = console.log;

class Bomb {
  constructor(id){
    this.id = id;
  }


  //定时器
  start() {
    log(`${this.id} 将在三秒后爆炸`);
    this.timerID = setTimeout(()=>{
     log(`${this.id} Boom!`);
    },3000); 
  }

  //取消定时
  clear() {
    clearTimeout(this.timerID);
    log(`${this.id} 是安全的`);
  }

  id;
  timerID;
}

let b1 = new Bomb(1);
b1.start();            //b1调用start

let b2 = new Bomb(2);
b2.start();           //b2调用start
setTimeout(b2.clear.bind(b2),1000); //b2在1秒钟后调用clear方法
